import 'dart:io';

import 'package:cjybase/widget/dialog_factory.dart';
import 'package:flutter/cupertino.dart';
import 'package:permission_handler/permission_handler.dart';

class PermissionUtil {
  /// 权限请求
  /// 传入对应权限
  ///     Permission.storage
  /// import 'package:permission_handler/permission_handler.dart';
  /// 权限列表详情查看 permission_android.txt 和 permission_ios.txt 文件
  static Future<bool> request(
      BuildContext context, Permission permission) async {
    await permission.request();
    if (Platform.isAndroid) {
      return await permission.isGranted;
    } else if (Platform.isIOS) {
      bool isGranted = await permission.isPermanentlyDenied;
      if (isGranted) {
        DialogFactory.contentBtn2Dialog(context, "提示", "是否跳转到APP设置中开启权限", () {},
            () {
          openAppSettings();
        });
        return false;
      } else {
        return true;
      }
    }
    return false;
  }
}
